package mammuthus.web.service

import java.net.URLEncoder
import net.csdn.common.path.Url

/**
 * 5/29/15 WilliamZhu(allwefantasy@gmail.com)
 */
trait ConfConfigure {
   this:SlaveService =>


  def addConfSystem(appName:String,slaves:String,confPath:String,params:Map[String,String])={

    val confTarget = s"/data/1/usr/local/configurations-auto"
    val autoCreateConfPath = if(params.contains("autoCreatePath")&&params("autoCreatePath")=="true") s"mkdir -p ${confPath};" else ""
    val shellCommand = URLEncoder.encode(s"mkdir -p $confTarget;${autoCreateConfPath} ln -s $confPath $confTarget/$appName", "utf-8")
    logger.info(new Url(shellURL).query(s"slaves=${slaves}&shellCommand=${shellCommand}").toString)
    val response = httpClient.get(new Url(shellURL).query(s"slaves=${slaves}&shellCommand=${shellCommand}"))

    val enableConfUrl = s"${masterUrl}/conf/control?${authTokenStr}slaves=${slaves}"
    httpClient.get(new Url(enableConfUrl))
    generateShellResult(response)
  }

}
